package com.sml.utils;


@SuppressWarnings("unchecked")
public class ThreadLocalUtil {

    //全局唯一的ThreadLocal对象，保证全局唯一，生命周期长，防止内存溢出
    private static final ThreadLocal<Object> THREAD_LOCAL = new ThreadLocal<>();

    //根据键获取值
    public static <T> T get() {
        return (T) THREAD_LOCAL.get();
    }

    //设置键值对
    public static void set(Object obj) {
        THREAD_LOCAL.set(obj);
    }

    //清除键值对，防止内存溢出
    public static void remove() {
        THREAD_LOCAL.remove();
    }
}
